<template>
  <el-dialog title="选择律师" :visible.sync="dialogVisible" width="800px" append-to-body>
    <el-form ref="queryForm" size="mini">
      <el-form-item prop="lewyerName">
        <el-input v-model="lewyerName" placeholder="搜索律师" @change="handleSearchName" />
      </el-form-item>
      <el-form-item>
        <div class="search-list">
          <span v-for="(item, index) in searchItem" :key="index" @click="handleSearchPinyin(item)">{{item}}</span>
        </div>
      </el-form-item>
    </el-form>
    <div v-loading="loading">
      <div class="lawyer-list">
        <div class="lawyer-item" v-for="(item, index) in list" :key="index">
          <el-image :src="item.lawyerCover | fullImgUrl() || 'https://static.minglvtang.com/images/placeholder/man.png'" style="width: 100px; height: 126px" />
          <div class="info">
            <div>
              <div class="name">{{ item.lawyerFullname }}</div>
              <div class="desc">{{ item.lawfirmName }}</div>
              <div class="uid">{{ item.uid }}</div>
            </div>
            <el-button type="primary" plain size="mini" @click="handleSelected(item)">选择</el-button>
          </div>
        </div>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import { getRelationLawyerList, getLawyerListByPinyin, getLawyerListByName } from "@/api/mobile/rankingList"
export default {
  data() {
    return {
      dialogVisible: false,
      searchItem: ['A','B','C','D','E','F','G','H','I','J','K',"L",'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'],
      lewyerName: null,
      list: [],
      loading: false
    }
  },
  created() {
    getRelationLawyerList().then(response => {
      this.list = response.data
    });
  },
  methods: {
    open() {
      this.dialogVisible = true;
    },
    handleSelected(item) {
      this.dialogVisible = false;
      this.$emit('selected', item);
    },
    getList() {
      this.loading = true
      getRelationLawyerList().then(response => {
        this.list = response.data
        this.loading = false
      })
    },
    handleSearchPinyin(item) {
      this.loading = true
      getLawyerListByPinyin(item).then(response => {
        this.list = response.data
        this.loading = false
      })
    },
    handleSearchName(item) {
      if(item) {
        this.loading = true
        getLawyerListByName(item).then(response => {
          this.list = response.data
          this.loading = false
        })
      }else {
        this.getList()
      }
    },
  }
}
</script>

<style lang="scss">
.lawyer-list {
  display: grid;
  gap: 20px;
  height: 50vh;
  overflow-y: auto;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.lawyer-item {
  display: flex;
  gap: 12px;
  .info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
  }
  .name {
    font-weight: bold;
    font-size: 14px;
  }
  .desc,
  .uid{
    font-size: 12px;
    color:#666;
  }
}

.search-list {
  display: flex;
  gap:12px;
  color: #207AFC;
  span {
    cursor: pointer;
  }
}
</style>
